require 'rexml/document'

class Interface

  attr_accessor :actions
  attr_accessor :events
  attr_accessor :namespace
  attr_accessor :package
  attr_accessor :interface
  attr_accessor :guards

  def initialize( xml_doc )

    loadInterface xml_doc

  end

  def loadInterface( xml_doc )

    xml_doc.elements.each { |element|

      buffer = Hash.new

      element.elements["Shapes"].each { |shape|
        case shape.attributes["MasterShape"]
          when "10" 
            buffer[:header] = shape.elements["Text"].text.chomp
          when "9" 
						if nil != shape.elements["Text"].text
							buffer[:body] = shape.elements["Text"].text.split("\n")
						end
        end
      }

      # Filter what was just decoded
      case buffer[:header].upcase
        when "NAMESPACE" 
          @namespace    = buffer[:body]
        when "PACKAGE"    
          @package      = buffer[:body]
        when "INTERFACE" 
          @interface    = buffer[:body]
        when "EVENTS"    
          @events       = buffer[:body]
        when "ACTIONS"   
          @actions      = buffer[:body]
        when "GUARDS"    
          @guards       = buffer[:body]
      end

    }

  end

  def printMenus
    puts "Namespace: #{@namespace}"
    puts "Package:   #{@package}"
    puts "Interface: #{@interface}"
    puts "Events:    #{@events}"
    puts "Actions:   #{@actions}"
    puts "Guards:    #{@guards}"

  end

end

